// 模拟挂号订单数据
const mockRegistrationOrders = [
  {
    id: 'R001',
    patientName: '王*柯',
    department: '内科',
    doctorName: '张医生',
    appointmentDate: '2024-01-15',
    appointmentTime: '09:00',
    status: '已完成',
    fee: 50,
    registrationNo: '20240115001',
    symptoms: '感冒，发热38.5度',
    diagnosis: '上呼吸道感染',
    treatment: '对症治疗，多休息'
  },
  {
    id: 'R002',
    patientName: '王*柯',
    department: '外科',
    doctorName: '李医生',
    appointmentDate: '2024-01-20',
    appointmentTime: '14:30',
    status: '待就诊',
    fee: 60,
    registrationNo: '20240120001',
    symptoms: '右腿疼痛',
    diagnosis: '待诊断',
    treatment: '待治疗'
  },
  {
    id: 'R003',
    patientName: '王*柯',
    department: '儿科',
    doctorName: '王医生',
    appointmentDate: '2024-01-25',
    appointmentTime: '10:00',
    status: '已取消',
    fee: 45,
    registrationNo: '20240125001',
    symptoms: '腹痛',
    diagnosis: '待诊断',
    treatment: '待治疗'
  }
]

// 模拟医嘱订单数据
const mockDoctorAdviceOrders = [
  {
    id: 'DA001',
    patientName: '王*柯',
    department: '内科',
    doctorName: '张医生',
    adviceDate: '2024-01-15',
    adviceType: '用药医嘱',
    status: '已完成',
    description: '感冒用药，每日三次，饭后服用',
    medicines: ['感冒灵颗粒', '维生素C片'],
    fee: 120,
    dosage: '感冒灵颗粒：每次1袋，每日3次；维生素C片：每次1片，每日3次',
    duration: '7天',
    notes: '多喝水，注意休息'
  },
  {
    id: 'DA002',
    patientName: '王*柯',
    department: '外科',
    doctorName: '李医生',
    adviceDate: '2024-01-20',
    adviceType: '检查医嘱',
    status: '待执行',
    description: '血常规检查，空腹12小时',
    medicines: [],
    fee: 80,
    preparation: '检查前12小时禁食',
    location: '检验科3楼',
    notes: '请携带身份证和检查单'
  },
  {
    id: 'DA003',
    patientName: '王*柯',
    department: '儿科',
    doctorName: '王医生',
    adviceDate: '2024-01-25',
    adviceType: '治疗医嘱',
    status: '执行中',
    description: '物理治疗，每日一次',
    medicines: [],
    fee: 200,
    treatmentPlan: '热敷治疗，每次20分钟',
    frequency: '每日1次',
    notes: '避免剧烈运动'
  }
]

// 获取挂号订单列表
export const fetchRegistrationOrders = async () => {
  // 模拟API调用延迟
  return new Promise((resolve) => {
    setTimeout(() => {
      resolve({
        success: true,
        data: mockRegistrationOrders,
        total: mockRegistrationOrders.length
      })
    }, 500)
  })
}

// 获取医嘱订单列表
export const fetchDoctorAdviceOrders = async () => {
  // 模拟API调用延迟
  return new Promise((resolve) => {
    setTimeout(() => {
      resolve({
        success: true,
        data: mockDoctorAdviceOrders,
        total: mockDoctorAdviceOrders.length
      })
    }, 500)
  })
}

// 获取挂号订单详情
export const fetchRegistrationOrderDetail = async (orderId) => {
  const order = mockRegistrationOrders.find(o => o.id === orderId)
  return new Promise((resolve) => {
    setTimeout(() => {
      if (order) {
        resolve({
          success: true,
          data: order
        })
      } else {
        resolve({
          success: false,
          message: '订单不存在'
        })
      }
    }, 300)
  })
}

// 获取医嘱订单详情
export const fetchDoctorAdviceOrderDetail = async (orderId) => {
  const order = mockDoctorAdviceOrders.find(o => o.id === orderId)
  return new Promise((resolve) => {
    setTimeout(() => {
      if (order) {
        resolve({
          success: true,
          data: order
        })
      } else {
        resolve({
          success: false,
          message: '医嘱不存在'
        })
      }
    }, 300)
  })
}

// 取消挂号订单
export const cancelRegistrationOrder = async (orderId) => {
  return new Promise((resolve) => {
    setTimeout(() => {
      resolve({
        success: true,
        message: '订单取消成功'
      })
    }, 500)
  })
}

// 执行医嘱
export const executeDoctorAdvice = async (orderId) => {
  return new Promise((resolve) => {
    setTimeout(() => {
      resolve({
        success: true,
        message: '医嘱执行成功'
      })
    }, 500)
  })
}

export default {
  fetchRegistrationOrders,
  fetchDoctorAdviceOrders,
  fetchRegistrationOrderDetail,
  fetchDoctorAdviceOrderDetail,
  cancelRegistrationOrder,
  executeDoctorAdvice
}
